Xceed DataGrid for Silverlight Documentation
Exporting Data

Xceed DataGrid for Silverlight provides synchronous and asynchronous XML spreadsheet format (xmlss) exporting capabilities with the resulting documents supported by Excel 2002 and up as well as by the Microsoft Office Web Components Spreadsheet Component. Data can also be exported to the comma-separate value (CSV) format, which is compatible with a wide variety of applications. 

Exporting to XML Spreadsheet and CVS Formats

Through the XmlssExporter and CsvExporter classes, the entire content of a grid, or a specific selection of data items, can be exported to an XMLSS or CSV-formatted stream, which can then be written to disk, the clipboard, etc. 

In order to begin an asynchronous export operation, the BeginExport method must be called specifying the stream to which the data items will be exported, the data items to export, as well as the AsyncCallback that will be called once the export operation completes.If the BeginExport method returns an IAsyncResult that indicates that the completed operation synchronously (i.e., IsCompleted is true), then the EndExport method can be called immediately after BeginExport. If the IAsyncResult indicates that the export operation is not completed (i.e., asynchronous operation), then the EndExport method will need to be called in the callback. In either case, the stream must be closed and disposed of after the EndExport method has been called.

The CancelExport method allows the export operation to be canceled at any time during the operation; however, rather than discarding the data that has already been exported, it will call the end-export callback, resulting in a valid, albeit partial, document. 

Because only one export operation can be executed at a time, it is recommended to disable any buttons or controls that launch export operations until the current operation completes.
The XmlssExporter and CsvExporter classes also expose the Export method, which can be used to synchronously export data items; however, it can only be used with a non-asynchronous data source (e.g., local list) and the UI will be "frozen" until the operation returns. It is highly recommended to only use this method if a small amount of data items are to be exported.

The IncludeColumnHeaders property indicates whether column headers will be exported alongside the data (by default, true). By default, the column titles (see Title property) are displayed in the column headers. If the UseFieldNamesInHeaders property is set to true, the column field names will be used instead.

The XmlssExporter class also defines the UseFixedHeaderRow property, which indicates whether the row that displays the column headers remains fixed and always visible above the exported data items.

How the exported data is formatted when using the CsvExporter class is determined by the CsvFormatSettings through which various format settings can be defined. The DateTimeFormat, FloatingPointFormat, and NumericFormat properties define how date-time, floating-point, and numeric values are formatted, respectively. The NewLine property defines the string that will be used at the end of each row, including any headers, to indicate a new line. Through the Separator property, the character that will be used to separate the fields in a row can be defined, while the TextDelimiter property defines the character used to delimit the value of a string, date, or numeric field if it contains a white space.

Asynchronous exporting to XML spreadsheet format

Synchronous exporting to the clipboard using CSV format

When exporting data items to the clipboard for the first item, a prompt will be displayed by Silverlight asking if access to the clipboard is to be granted for the application.

Send Feedback